package QuanLyDatHang;

import KetNoiSQL.KetNoiSQL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class DatHang {

    private int maDatHang;
    private int maKhachHang;
    private String tenKhachHang;
    private String thoiGianGiaoHang;
    private String diaChiGiaoHang;
    private int maThuoc;
    private String tenThuoc;
    private int soLuong;
    private int gia;

    public int getGia() {
        return gia;
    }

    public void setGia(int gia) {
        this.gia = gia;
    }

    public int getMaDatHang() {
        return maDatHang;
    }

    public void setMaDatHang(int maDatHang) {
        this.maDatHang = maDatHang;
    }

    public int getMaKhachHang() {
        return maKhachHang;
    }

    public void setMaKhachHang(int maKhachHang) {
        this.maKhachHang = maKhachHang;
    }

    public String getTenKhachHang() {
        return tenKhachHang;
    }

    public void setTenKhachHang(String tenKhachHang) {
        this.tenKhachHang = tenKhachHang;
    }

    public String getThoiGianGiaoHang() {
        return thoiGianGiaoHang;
    }

    public void setThoiGianGiaoHang(String thoiGianGiaoHang) {
        this.thoiGianGiaoHang = thoiGianGiaoHang;
    }

    public String getDiaChiGiaoHang() {
        return diaChiGiaoHang;
    }

    public void setDiaChiGiaoHang(String diaChiGiaoHang) {
        this.diaChiGiaoHang = diaChiGiaoHang;
    }

    public int getMaThuoc() {
        return maThuoc;
    }

    public void setMaThuoc(int maThuoc) {
        this.maThuoc = maThuoc;
    }

    public String getTenThuoc() {
        return tenThuoc;
    }

    public void setTenThuoc(String tenThuoc) {
        this.tenThuoc = tenThuoc;
    }

    public int getSoLuong() {
        return soLuong;
    }

    public void setSoLuong(int soLuong) {
        this.soLuong = soLuong;
    }

    //Xem ds người đặt hàng
    public static Vector xemDanhSachDatHang() throws SQLException {
        Vector v = new Vector();

        ResultSet rs = KetNoiSQL.thucHienTruVan("spXemDatHang");
        while (rs.next()) {
            DatHang dh = new DatHang();
            dh.maDatHang = rs.getInt(1);
            dh.tenKhachHang = rs.getString(2);
            dh.thoiGianGiaoHang = rs.getString(3);
            dh.diaChiGiaoHang = rs.getString(4);
            dh.tenThuoc = rs.getString(5);
            dh.soLuong = rs.getInt(6);
            dh.gia = rs.getInt(7);

            v.add(dh);
        }

        return v;
    }
    //Lấy mã đặt hàng vào combobox

    public static Vector xemDatHang() throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spXemBangDatHang");
            while (rs.next()) {
                DatHang dh = new DatHang();
                dh.maDatHang = rs.getInt(1);
                dh.tenKhachHang = rs.getString(2);
                dh.thoiGianGiaoHang = rs.getString(3);
                dh.diaChiGiaoHang = rs.getString(4);
                v.add(dh);
            }
        } catch (SQLException ex) {
        }
        return v;
    }
    //Thêm người đặt hàng vào bảng đặt hàng

    public static int themDatHang(DatHang dh) throws SQLException {
        int i = 0;
        Vector dsThamSo = new Vector();
        dsThamSo.add(dh.maKhachHang);
        dsThamSo.add(dh.thoiGianGiaoHang);
        dsThamSo.add(dh.diaChiGiaoHang);
        i = KetNoiSQL.thucHienCapNhat("spThemDatHang", dsThamSo);

        return i;
    }

    //Thêm người đặt hàng vào bảng chi tiết đặt hàng
    public static int themCTDatHang(DatHang dh) throws SQLException {
        int i = 0;
        Vector dsThamSo = new Vector();
        dsThamSo.add(dh.maDatHang);
        dsThamSo.add(dh.maThuoc);
        dsThamSo.add(dh.soLuong);
        i = KetNoiSQL.thucHienCapNhat("spThemCTDatHang", dsThamSo);

        return i;
    }

    //Xóa Đặt hàng
    public static int xoaDatHang(int maDatHang) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(maDatHang);
            i = KetNoiSQL.thucHienCapNhat("spXoaDatHang", dsThamSo);
        } catch (SQLException sqlex) {
        }
        return i;
    }

    //Tìm kiếm đặt hàng
    public static Vector timKiem(String tenSP, Vector timKiem) throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan(tenSP, timKiem);
            while (rs.next()) {
                DatHang tkdh = new DatHang();
                tkdh.maDatHang = rs.getInt(1);
                tkdh.tenKhachHang = rs.getString(2);
                tkdh.thoiGianGiaoHang = rs.getString(3);
                tkdh.diaChiGiaoHang = rs.getString(4);
                tkdh.tenThuoc = rs.getString(5);
                tkdh.soLuong = rs.getInt(6);
                tkdh.gia = rs.getInt(7);

                v.add(tkdh);

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;

    }
}
